﻿using Microsoft.Xna.Framework;
using RaptorEngine.Threads;

namespace RaptorEngine.Components.Drawable
{
	public abstract class Drawable : Component
	{
		internal ComponentType type;
		internal Matrix worldMatrix;

		private readonly int _id;
		public int Id
		{
			get { return _id; }
		}

        /// <summary>The data used by the draw-thread</summary>
		internal bool visible;
        /// <summary>The data used by the update-thread</summary>
		private bool _visible;
        /// <summary>Directly sets the data used by the update-thread
        /// and sends a change message to update the render-thread</summary>
		public bool Visible
		{
			get { return _visible; }
			set
			{
				_visible = value;
				GameEngine.Instance.UpdateBuffer.Add(new ChangeMessage
				    {
						MessageType = ChangeMessageType.UpdateVisible,
						ID = _id,
						Visible = value
					});
			}
		}

        /// <summary>The data used by the draw-thread</summary>
		internal string textString;
        /// <summary>The data used by the update-thread</summary>
		private string _textString;
        /// <summary>Directly sets the data used by the update-thread
        /// and sends a change message to update the render-thread</summary>
		public string TextString
		{
			get { return _textString; }
			set
			{
				_textString = value;
				GameEngine.Instance.UpdateBuffer.Add(new ChangeMessage
				    {
						MessageType = ChangeMessageType.UpdateTextString,
						ID = _id,
						TextString = value
					});
			}
		}

        /// <summary>The data used by the draw-thread</summary>
		internal int animationState;
        /// <summary>The data used by the update-thread</summary>
		private int _animationState;
        /// <summary>Directly sets the data used by the update-thread
        /// and sends a change message to update the render-thread</summary>
		public int AnimationState
		{
			get { return _animationState; }
			set
			{
				_animationState = value;
				GameEngine.Instance.UpdateBuffer.Add(new ChangeMessage
				    {
					MessageType = ChangeMessageType.UpdateAnimationState,
					ID = _id,
					AnimationState = value
				});
			}
		}


		public Drawable(Entity e, ComponentType componentType)
            : base(e, componentType)
		{
			_id = e.Id;
			type = componentType;
			worldMatrix = e.WorldMatrix;
			GameEngine.Instance.Render.AddNewData(this);
		}
        public Drawable(Entity e, ComponentType componentType, string text)
            : this(e, componentType)
        {
            _textString = text;
            textString = _textString;
        }
	}
}
